#ifndef CGUIMANAGER_H_
#define CGUIMANAGER_H_

#include <algorithm>
#include "cbutton.h"
#include "ccombobox.h"
#include "cdialog.h"
#include "cedit.h"
#include "cguidefaultstylesloader.h"
#include "cguilistener.h"
#include "clabel.h"
#include "cspinbox.h"
#include "../event/cmouseclickevent.h"
#include "../event/cmousemoveevent.h"
#include "../event/ckeyboardevent.h"

// Comparison object for z axis of dialog (lesser)
struct TLesserZ : binary_function<const CDialog*, const CDialog*, bool> {
  bool operator()(const CDialog* a, const CDialog* b) const {
    return a->getZ() < b->getZ();
  }
};

// Comparison object for z axis of dialog (greater)
struct TGreaterZ : binary_function<const CDialog*, const CDialog*, bool> {
  bool operator()(const CDialog* a, const CDialog* b) const {
    return a->getZ() > b->getZ();
  }
};

/**
 * CGuiManager - class managing aside 2D gui
 * @author Michal Rost
 * @date 06.04.2008
 */
class CGuiManager : public CObject {
public:
  CGuiManager();
  virtual ~CGuiManager();
  void addDialogPtr(CDialog* dialogPtr);
  void setRendererPtr(CGuiRenderer* rendererPtr);
  void setListenerPtr(CGuiListener* listenerPtr);
  void applyStyle(string fileName, CLogger* logPtr = NULL);
  void dispatchEvent(CEvent* eventPtr);
  void drawGui();
  static string getClassName() {
    return "CGuiManager";
  }
protected:
  CGuiRenderer* rendererPtr;
  CGuiListener* listenerPtr;
  CDynamicGuiObject* focusObjPtr;
  CDynamicGuiObject* prelightObjPtr;
  vector<CDialog*> dialogs;
  void resetComponentStatus(CDynamicGuiObject* compPtr);
  void processDialog(vector<CAPFNode*>::const_iterator node);
  void readStatusStylesFromAPFNode(vector<CAPFNode*>::const_iterator node,
      CGuiStyle &styleNormal, CGuiStyle &stylePrelight,
      CGuiStyle &styleFocus, CGuiStyle &styleDisabled);
  CGuiStyle readStyleFromAPFNode(vector<CAPFNode*>::const_iterator node);
  CBorder readBorderFromAPFNode(vector<CAPFNode*>::const_iterator node);
};

#endif
